home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1 / Ian and Stuart's One (Australia).iso / Australasian Legends / Commercial / Rainbow Hill / MacDOS™ 2.0.0 / batches / uniqueTempName.bat < prev    next >
DOS Batch File  |  1994-06-19  |  2KB  |  55 lines

  1. @echo off
  2. !  uniqueTempName.bat    Returns a unique temporary file name
  3. !
  4. !  uniqueTempName varName [path]
  5. !
  6. !  where 'varName' is a string containing the name of the global variable into
  7. !  which the unique file name is to be returned. 'path' identifies the folder where
  8. !  the file name should be unique. If 'path' is missing, the current folder is assumed.
  9. !
  10. !  Copyright © 1994 by Rainbow Hill Pty Ltd. All rights reserved.
  11. !
  12.  
  13.     ! ensure that the first parameter is there and that the third one is not
  14.     set doserr=13
  15.     if not "%3 " == " " goto ERR_LBL
  16.     if "%1 " == " " goto ERR_LBL
  17.     onerror ERR_LBL
  18.  
  19.     ! determine the folder in which the file name should be unique
  20.     set uniqueTempName_folder=%WHERE%
  21.     if "%2 " == " " goto FOLDER_OK_LBL
  22.     set doserr=27
  23.     if not existdir "%2" goto ERR_LBL
  24.     set uniqueTempName_folder=%2
  25. :FOLDER_OK_LBL
  26.  
  27.     ! initialise the sequence of unique file names (all capitals so that they are visible)
  28.     set uniqueTempName_root=MACDOS-TEMP-
  29.     set uniqueTempName_seq=0
  30.  
  31. :TRYNAME_LBL
  32.     ! keep trying with new names until you find one that does not exist
  33.     set uniqueTempName_name=%uniqueTempName_root%%uniqueTempName_seq%
  34.     if exist "%uniqueTempName_folder%\%uniqueTempName_name%" goto NEXTNAME_LBL
  35.     if not existdir "%uniqueTempName_folder%\%uniqueTempName_name%" goto FOUND_LBL
  36. :NEXTNAME_LBL
  37.     incr uniqueTempName_seq
  38.     goto TRYNAME_LBL
  39.  
  40. :FOUND_LBL
  41.     ! save the name into the variable specified by the caller
  42.     set %1=%uniqueTempName_name%
  43.     set doserr=0
  44.     goto DONE_LBL
  45.  
  46. :ERR_LBL
  47.     show %doserr%
  48.  
  49. :DONE_LBL
  50.     ! remove the temporary variables
  51.     set uniqueTempName_name=
  52.     set uniqueTempName_root=
  53.     set uniqueTempName_seq=
  54.     set uniqueTempName_folder=
  55.